# -*- coding: utf-8 -*-
# @Time : 2021/9/9 15:09
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : test_shangji.py
# @Project : crm
'''验证添加合同功能'''

from time import sleep
import time
from selenium.webdriver.common.by import By
from selenium import webdriver
from utils.get_cookie import cookie
from utils import util
#定位器
tianjiahetong_locator=(By.XPATH,"/html/body/div[5]/div[2]/div[1]/div/a")
hetongbianhao_locator=(By.CSS_SELECTOR,"#number")
qianyueshijian_locator=(By.CSS_SELECTOR,"#due_time")
shangji_locator=(By.CSS_SELECTOR,"#business_name")
shangji_xuanzhe_locator=(By.XPATH,'//*[@id="data"]/tr[1]/td[1]/input[1]')
shangji_queren_locator=(By.XPATH,"/html/body/div[7]/div[3]/div/button[1]")
fzr_locator=(By.CSS_SELECTOR,"#owner_name")
fzr_xz_locator=(By.XPATH,'//*[@id="d_content"]/tr[1]/td[1]/input')
fzr_queren_locator=(By.XPATH,'/html/body/div[8]/div[3]/div/button[1]')
hetongjine_locator=(By.ID,"price")
shengxiaoshijian_locator=(By.CSS_SELECTOR,"#start_date")
daoqishijian_locator=(By.CSS_SELECTOR,"#end_date")
tiaokuan_locator=(By.TAG_NAME,"body")
miaoshu_locator=(By.CSS_SELECTOR,"#description")
baocuen_locator=(By.XPATH,"/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]")
#前提条件
cookie=cookie(util.HOST,util.name,util.password)
driver=webdriver.Chrome()
driver.add_cookie(cookie)
driver.get('http://192.168.1.155/crm/index.php?m=contract')

#测试用例步骤
try:
    #进入添加合同页面
    driver.find_element(*tianjiahetong_locator).click()
    # 输入合同编号
    hetongbianhao_element=driver.find_element(*hetongbianhao_locator)
    hetongbianhao_element.clear()
    hetongbianhao_element.send_keys("gvbn")
    # 输入合同签约时间
    now = time.strftime("%Y-%m-%d")
    driver.find_element(*qianyueshijian_locator).send_keys(now)
    #选择商机
    driver.find_element(*shangji_locator).click()
    driver.find_element(*shangji_xuanzhe_locator).click()
    driver.find_element(*shangji_queren_locator).click()
    #选择负责人
    driver.find_element(*fzr_locator).click()
    driver.find_element(*fzr_xz_locator).click()
    driver.find_element(*fzr_queren_locator).click()
    #输入合同金额
    driver.find_element(*hetongjine_locator).send_keys(123)
    #输入合同生效时间
    driver.find_element(*shengxiaoshijian_locator).send_keys("now")
    #输入合同到期时间
    driver.find_element(*daoqishijian_locator).send_keys("2027-09-17")
    #输入条款
    driver.switch_to.frame(0)
    driver.find_element(*tiaokuan_locator).send_keys("不许反法")
    #输入合同描述
    driver.switch_to.parent_frame()
    driver.find_element(*miaoshu_locator).send_keys("初次合作")
    #点击保存
    driver.find_element(*baocuen_locator).click()

except Exception as e:
    raise e
finally:
    sleep(5)
    driver.quit()